﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows;

namespace RaSuperGrid.SuperGrid.Converter
{
    class HeaderValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int type = System.Convert.ToInt32(parameter);

            switch (type)
            {
                case 1:
                {
                    return value.ToString();
                }
                case 2:
                {
                    string s = value.ToString();

                    if (string.IsNullOrEmpty(s))
                        return "True";
                    else
                        return "False";
                }
                case 3:
                {
                    int width = System.Convert.ToInt32(value);

                    if (width - 5 >= 0)
                        return width - 5;
                    else
                        return width;
                }
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int type = System.Convert.ToInt32(parameter);

            switch (type)
            {
                case 1:
                {
                    string s = value.ToString();

                    if (string.IsNullOrEmpty(s))
                        return DependencyProperty.UnsetValue;
                    else
                        return s;
                }
            }

            return DependencyProperty.UnsetValue;
        }
    }
}
